package com.baizhi.wj.controller;

import com.baizhi.wj.dto.CategoryDTO;
import com.baizhi.wj.entity.Category;
import com.baizhi.wj.ov.AddVO;
import com.baizhi.wj.ov.CategoryOV;
import com.baizhi.wj.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.swing.plaf.SpinnerUI;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("category")
@CrossOrigin
public class CategoryCpntroller {
    @Autowired
    private CategoryService categoryService;


    @RequestMapping("queryOnePage")
    @ResponseBody
    public CategoryOV queryOnePage(@RequestBody  CategoryDTO categoryDTO){
     return categoryService.queryByPage(categoryDTO);
    }
    @RequestMapping("queryTwoPage")
    @ResponseBody
    public CategoryOV queryTwoPage(@RequestBody  CategoryDTO categoryDTO){
        return categoryService.queryTwoPage(categoryDTO);
    }
    @RequestMapping("add")
    @ResponseBody
    public Map<String,Object> add(@RequestBody Category category){

       return categoryService.insiger(category);
    }
    @RequestMapping("delete")
    @ResponseBody
    public  Map<String,Object> delete(@RequestBody Category category){
       return categoryService.delete(category);
    }
  /*  @RequestMapping("queryById")
    @ResponseBody
    public  Map<String,Object> queryById(@RequestBody Category category){
        return  categoryService.selectOne(category);
    }*/
  @RequestMapping("queryById")
  @ResponseBody
  public  Category queryById(int id){
      return categoryService.selectOne(id);
  }
    @RequestMapping("queryByLevelsCategory")
    @ResponseBody
    public  List<Category> queryByLevelsCategory(int levels ){

        return categoryService.selectAll(levels);
    }
    @RequestMapping("update")
    @ResponseBody
    public Map<String, Object> update(@RequestBody Category category){
      return categoryService.update(category);
    }
}

